﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static UnityEngine.GraphicsBuffer;
using UnityEditor;
using UnityEngine;

#if UNITY_EDITOR

[CustomEditor(typeof(RedDotTrigger))]
public class RedDotTriggerEditor : Editor
{
    private RedDotTrigger cmp = null;
    private SerializedProperty redDotType;
    private SerializedProperty redDotTriggerType;
    private SerializedProperty targetGameObject;
    private List<string> nodePathList;

    void OnEnable()
    {
        cmp = (RedDotTrigger)target;

        redDotType = serializedObject.FindProperty("redDotType");
        redDotTriggerType = serializedObject.FindProperty("redDotTriggerType");
        targetGameObject = serializedObject.FindProperty("targetGameObject");

        nodePathList = RedDotEditorUtil.GetNodeTreeList();
    }

    public override void OnInspectorGUI()
    {
        EditorGUILayout.PropertyField(redDotType);
        EditorGUILayout.PropertyField(redDotTriggerType);
        EditorGUILayout.PropertyField(targetGameObject);

        if (serializedObject.hasModifiedProperties)
        {
            serializedObject.ApplyModifiedProperties();
        }

        EditorGUILayout.Space(10);

        bool dirty = false;

        var idx = nodePathList.IndexOf(cmp.treePath);
        var idxNew = EditorGUILayout.Popup("监听路径", idx, nodePathList.ToArray());
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel("重置路径");
        if (GUILayout.Button("重置"))
        {
            idxNew = 0;
        }
        EditorGUILayout.EndHorizontal();
        if (idxNew >= 0 && nodePathList.Count > idxNew && idxNew != idx)
        {
            cmp.treePath = nodePathList[idxNew];
            dirty = true;
        }

        if (dirty)
        {
            EditorUtility.SetDirty(target);
        }
    }
}
#endif